EEPROM INTERFACING WITH 8051
The EEPROM is the permanent storage devices and can be erased and reprogrammed whenever we need.
Synopsis

The EEPROM is the permanent storage devices and can be erased and reprogrammed whenever we need. These are the kinds of nonvolatile storage chip means when power is removed the content of the memory remains intact. It has no impact of power failure. EEPROM stands for Electrically Erasable Programmable Read Only Memory. The main advantage of this memory is that it can be erased and re programmed at any time. We can edit the content at particular location or remove the content from the particular location within the EEPROM chip. That is EEPROM. Here are so many EEPROM chips are available in the market by different reputed manufacturer but specially the most popular product if 24CXX series. All EEPROM uses I2C interface protocol to communicate with the 8051 microcontroller (AT89S52) and vice versa.

Description

The 24XXX series serial EEPROMs from the Technology support a bidirectional, 2-wire bus and data transmission protocol. The bus is controlled by the microcontroller (master), which generates the Serial Clock (SCL), controls the bus access and generates the Start and Stop conditions, while the 24XXX serial EEPROM works as slave. The 24XXX serial EEPROMs are I2C™ compatible and have maximum clock frequencies ranging from 100 kHz to 1 MHz

Introduction to I2C

The I2C (Inter-Integrated Circuit) bus is a 2-wire serial bus which provides a small networking system for circuits sharing a common bus. The devices on the bus can vary from microcontrollers to LCD drivers to E2PROMs. Two bi-directional lines, a serial data (SDA) and a serial clock (SCL) line, transmit data between the devices connected to the bus. Each device has a unique address to differentiate it from the other devices on the bus, and each is configured either as a master or a slave when performing data transfers (see Table 1). A master is the device which initiates a data transfer and generates the clock signals necessary for the transfer. Any device that is addressed is considered a slave. The I2C bus is a multi-master bus, which means that more than one device that is capable of controlling the bus can be connected to it. Each transmission on the bus begins with the Master sending a Start condition and ends with a Stop condition (see Figure 1). The Master then sends the address of the particular slave device it is requesting. The first four bits of this slave address are fixed as 1010. The next three bits specify a combination of the device address bit(s) and which 2K array of the memory is being addressed (see Figure 2). The last bit of the slave address specifies whether a read or write operation is to be performed. When this bit is a “1”, a read operation is performed, and when it is a “0”, a write operation is performed. After the Master sends a Start condition, the slave (EEPROM) monitors the bus and responds with acknowledge when its address matches the transmitted slave address (see Figure 3). The device then performs a read or write operation depending on the state of the R/W bit.





CAT24CXX Interface to 8051 Microcontroller:

Catalyst’s I2C family of devices interfaces directly with industry standard microcontrollers such as the Intel MCS-51 family. This family includes 8031/8051 and 8032/8052 (ROM less/ROM) family types. Catalyst I2C E2PROMs are 2-wire interface, nonvolatile memories ranging from 2K bits (CAT24WC02) to 64K bits (CAT24WC64) in density. They adhere to the I2C protocol which uses 2 lines, a data (SDA) and serial clock (SCL) line for all transmissions, as described above. The CAT24WC02 E2PROM has an 8 byte page write buffer and a write protect pin for inadvertent write protection.

The CAT24WC04, CAT24WC08 and CAT24WC16 devices have 16 byte page write buffers. Up to eight CAT24WC02 devices, four CAT24WC04 devices, two CAT24WC08 devices and one CAT24WC16 device may be connected to an I2C bus and addressed independently.

The CAT24WC32/64 has a 32-byte Page Write buffer and up to eight devices may be connected to an I2C bus and addressed independently. Unique addressing is accomplished through hard-wiring address pins A0, A1 and A2 on each device. An example program follows that demonstrates simple byte write and byte read routines as well as page mode and sequential read routines using an 8051 microcontroller. Figure 4 shows a simple hardware interface.

The main features of the 24XXX serial EEPROMs are:

• 2-wire serial interface bus, I2C compatible

• EEPROM densities from 128 bits to 512 Kbits

• Bus speed from 100 kHz to 1 MHz

• Bus speed from 100 kHz to 1 MHz

• Low power operation

• Temperature range from -40°C to +125°C

• Over 1,000,000 erase/write cycles

• Up to 8 devices may be connected to same bus

Proteus design for EEPROM interfacing with 8051


Orcad design for EEPROM interfacing with 8051


Interfacing of EEPROM with 8051

/*  Name     : main.c
 *  Purpose  : Source code for Serial EEPROM AT24C02 with AT89C52.
 *  Author   : Gemicates
 *  Date     : 2014-02-29
 *  Website  : www.gemicates.org
 *  Revision : None
 */
 
//Program to interface Serial EEPROM AT24C02 with 8051 microcontroller 
#include <REGX52.H>
#include<intrins.h>   			              // For using [_nop_()]
sbit sda=P1^0;
sbit scl=P1^1;
sbit SW2=P1^2;
sbit SW3=P1^3;
sbit SW4=P1^4;
bit ack;

//sfr output=0x80;				      // p0 port
sfr output=0x90;				      // p1 port
sfr lcd_data_pin=0xA0;			              // p2 port
//sfr output=0xB0;				      // p3 port

sbit rs=P3^2;
sbit rw=P3^3;
sbit en=P3^4;
sbit led=P3^5;
sbit led1=P3^6;
sbit SW1=P3^7;
unsigned char reead,write,write2,i,j,k,l;
unsigned int temp;
void delay(unsigned int count)
{
        int i,j;
        for(i=0;i<count;i++)
                for(j=0;j<1275;j++);
}
void lcd_command(unsigned char comm)
{
        lcd_data_pin=comm;
        en=1;
        rs=0;
        rw=0;
        delay(1);
        en=0;
}
void lcd_data(unsigned char disp)
{
        lcd_data_pin=disp;
        en=1;
        rs=1;
        rw=0;
        delay(1);
        en=0;
}
void lcd_dataa(unsigned char *disp)
{
        int x;
        for(x=0;disp[x]!=0;x++)
        {
                lcd_data(disp[x]);
        }
}
void lcd_ini()
{
        lcd_command(0x38);                            // for using 8-bit 2 row LCD
        delay(5);
        lcd_command(0x0F);                            // for display on, cursor blinking
        delay(5);
        lcd_command(0x80);
        delay(5);
}
void aknowledge()                                     // acknowledge condition
{
        scl=1;
        _nop_();
        _nop_();
        scl=0;
}
void start()                                          // start condition
{
        sda=1;
        scl=1;
        _nop_();                                      // No operation
        _nop_();
        sda=0;
        scl=0;
}
void stop()                                           // stop condition
{
        sda=0;
        scl=1;
        _nop_();
        _nop_();
        sda=1;
        scl=0;
}
void send_byte(unsigned char value)                   // send byte serially
{
        unsigned int i;
        unsigned char send;
        send=value;
        for(i=0;i<8;i++)
        { 
                sda=send/128;                         // extracting MSB
                send=send<<1;                         // shiftng left
                scl=1;
                _nop_();
                _nop_();
                scl=0;
        }
   ack=sda;                                           // reading acknowledge
   sda=0;
}
unsigned char read_byte()                             // reading from EEPROM serially
{
        unsigned int i;
        sda=1;
        reead=0;
        for(i=0;i<8;i++)
        {
                reead=reead<<1;
                scl=1;
                _nop_();
                _nop_();
                if(sda==1)
                        reead++;
                scl=0;
        }
        sda=0;
        return reead;                                 // Returns 8 bit data here
}
void save()                                           // save in EEPROM
{
        start();
        send_byte(0xA0);                              // device address
        aknowledge();
        send_byte(0x0000);                            // word address
        aknowledge();
        send_byte('G');                               // send data
        aknowledge();
        send_byte('E');
				aknowledge();
        send_byte('M');
				aknowledge();
        send_byte('I');                               // send data
        aknowledge();
        send_byte('C');
				aknowledge();
        send_byte('A');
        aknowledge();
				send_byte('T');       // send data
        aknowledge(); 
        send_byte('E');
				aknowledge();
        send_byte('S');
        aknowledge();
        stop();
        if(ack==0)
        {
                led=0;
                delay(100);
                lcd_command(0x86);
                lcd_data('G');
                lcd_command(0x87);
                lcd_data('E');
								lcd_command(0x88);
                lcd_data('M');
                lcd_command(0x89);
                lcd_data('I');
								lcd_command(0x8A);
                lcd_data('C');
                lcd_command(0x8B);
                lcd_data('A');
								lcd_command(0x8C);
                lcd_data('T');
								lcd_command(0x8D);
                lcd_data('E');
                lcd_command(0x8E);
                lcd_data('S');
								led=1;
                delay(100);
        }
        else
        led1=0;
				aknowledge();
}

void Read()
{
        start();
        send_byte(0xA0);
        aknowledge();
        send_byte(0x0000);
        aknowledge();
        start();
        send_byte(0xA1);                              // device address
        aknowledge();
        i=read_byte();
        aknowledge();
        j=read_byte();
        aknowledge();
				k=read_byte();
        aknowledge();
				l=read_byte();
        aknowledge();
        stop();
		if(i!=0xff)
		{
				led1=0;
        delay(100);
        write=i;
        lcd_command(0xC6);
        lcd_data(write);
				write=j;
        lcd_command(0xC7);
        lcd_data(write);
				write=k;
        lcd_command(0xC8);
        lcd_data(write);	
			  write=l;
        lcd_command(0xC9);
        lcd_data(write);
				led1=1;
        delay(100);
			
		}
}

void Read_dep()
{
        start();
        send_byte(0xA0);
        aknowledge();
        send_byte(0x0004);
        aknowledge();
        start();
        send_byte(0xA1);                              // device address
        aknowledge();
        i=read_byte();
        aknowledge();
        j=read_byte();
        aknowledge();
				k=read_byte();
        aknowledge();
				l=read_byte();
        aknowledge();
        stop();
		if(i!=0xff)
		{
				led1=0;
        delay(100);
        write=i;
        lcd_command(0xC6);
        lcd_data(write);
				write=j;
        lcd_command(0xC7);
        lcd_data(write);
				write=k;
        lcd_command(0xC8);
        lcd_data(write);
				write=l;
        lcd_command(0xC9);
        lcd_data(write);
				led1=1;
        delay(100);			
			
		}
}

void Read_session()
{
        start();
        send_byte(0xA0);
        aknowledge();
        send_byte(0x0002);
        aknowledge();
        start();
        send_byte(0xA1);                              // device address
        aknowledge();
        i=read_byte();
        aknowledge();
        j=read_byte();
        aknowledge();
				k=read_byte();
				aknowledge();
				l=read_byte();
        aknowledge();
        stop();
		if(i!=0xff)
		{
				led1=0;
        delay(100);
        write=i;
        lcd_command(0xC6);
        lcd_data(write);
				write=j;
        lcd_command(0xC7);
        lcd_data(write);
				write=k;
        lcd_command(0xC8);
        lcd_data(write);
				write=l;
        lcd_command(0xC9);
        lcd_data(write);
				led1=1;
        delay(100);
		
		}
}

int main()
{
			
        lcd_ini();
        lcd_dataa("Sent :");
        lcd_command(0xC0);
        lcd_dataa("Read :");
        temp=0;
        while(1)
        {
					if(SW1==0)
					{
										save();
					}
					if(SW2==0)
					{
										led1=0;
										Read();
										led1=1;
					}
					if(SW3==0)
					{
										led1=0;
										Read_dep();
										led1=1;
					}
					if(SW4==0)
					{
										led1=0;
										Read_session();
										led1=1;
					}
        }
                                                       // return 0;
}

Error message here!

Show Error message here!


Forgot your password?

Error message here!

Send OTP

Error message here!

Show Error message here!


Lost your password? Please enter your email address. You will receive a password you Need.

Send Error message here!


Back to log-in

Close